package com.example.consumer;

import com.example.alipay.PayInterface;

import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {
	private PayInterface pi;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Intent intent = new Intent("com.taobao.alipay");
		ServiceConnection conn = new ServiceConnection() {

			@Override
			public void onServiceDisconnected(ComponentName name) {
			}

			@Override
			public void onServiceConnected(ComponentName name, IBinder service) {
				pi = PayInterface.Stub.asInterface(service);
			}
		};
		bindService(intent, conn, BIND_ADJUST_WITH_ACTIVITY);
	}

	public void pay(View v) throws RemoteException {
		int result = pi.pay(200);
		Toast.makeText(getApplicationContext(), "支付成功" + result, 0).show();
	}
}
